﻿using System;
using System.Collections.Generic;
using Core;

namespace DataAccess
{
    public class NguoiDung_Info
    {
        #region KHAI BÁO CÁC ĐỐI TƯỢNG VÀ BIẾN CẦN DÙNG
        // Các thuộc tính của lớp 
        public int ID { get; set; }
        public string TenDangNhap { get; set; }
        public string Email { get; set; }
        public string MatKhau { get; set; }
        public string TenDayDu { get; set; }
        public string DiaChi { get; set; }
        public string SoDienThoai { get; set; }
        public bool HoatDong { get; set; }
        public bool QuanTri { get; set; }
        #endregion


        public static NguoiDung_Info NguoiDung_KiemTraTen(string username)
        {
            return CBO.FillObject<NguoiDung_Info>(DataProvider.Instance.ExecuteReader("sp_NguoiDung_KiemTraTen", username));
        }
        public static NguoiDung_Info NguoiDung_Chon(int ID)
        {
            return CBO.FillObject<NguoiDung_Info>(DataProvider.Instance.ExecuteReader("sp_NguoiDung_Chon", ID));
        }
        public static bool NguoiDung_Them(string username, string Email, string password, string fullname, string add, string phone, bool status)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("sp_NguoiDung_Them", username, Email, password, fullname, add,  phone,  status);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static NguoiDung_Info NguoiDung_KiemTraEmail(string Email)
        {
            return CBO.FillObject<NguoiDung_Info>(DataProvider.Instance.ExecuteReader("sp_NguoiDung_KiemTraEmail", Email));
        }
        public static bool NguoiDung_CapNhat(int ID, string Email, string pass, string fullname, string address, string phone, bool status)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("sp_NguoiDung_CapNhat", ID, Email, pass, fullname, address, phone, status);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool NguoiDung_CapNhat(NguoiDung_Info us)
        {
            return NguoiDung_CapNhat(us.ID, us.Email, us.MatKhau, us.TenDayDu, us.DiaChi, us.SoDienThoai, us.HoatDong);
        }

        public static bool NguoiDung_DoiMatKhau(int ID, string pass)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("sp_NguoiDung_DoiMatKhau", ID, pass);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static List<NguoiDung_Info> NguoiDungs_ChonTatCa()
        {
            return CBO.FillCollection<NguoiDung_Info>(DataProvider.Instance.ExecuteReader("sp_NguoiDungs_ChonTatCa"));
        }


        public static bool NguoiDung_Xoa(int ID)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("sp_NguoiDung_Xoa", ID);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
